**Analysis from Order Interventions at Immaculate Conception in Ithaca 
**Norbert Wilson, Auburn University

clear all
estimates clear
set more off


**To convert data where the clients could pick two deserts, I created variable BarNew 
**that coverts value over 1 to 1. There are only four instances of this in the data.

rename Treatment Order
rename Boxed Packaging
rename QNumber QueueNumber
label variable QueueNumber "Queue Number"
generate BarNew = Bars
replace BarNew=1 if BarNew>1
drop Bars 
rename BarNew Bars
label variable Bars "Bars with more than one selection noted as 1"


by Order Packaging, sort : egen float Average = mean(Bars)

label variable Average "Average over 10 observations"
label variable Order "Indicator of Back (0) or Front (1)"
label variable Packaging "Indicator of Unboxed (U) or Boxed (1) "

egen float Both = group(Order Packaging), label lname(BothName)

label define BothName 1 "Back Unboxed", modify
label define BothName 2 "Back Boxed", modify
label define BothName 3 "Front Unboxed", modify
label define BothName 4 "Front Boxed", modify

label define OrderTreatment 0 "Back" 1 "Front"
label define PackagingTreatment 0 "Unboxed" 1 "Boxed"
label values Order OrderTreatment
label values Packaging PackagingTreatment

label variable Average "Average over Front and Box which represents the four data collection days."
label variable Order "Indicator of Back (0) or Front (1)"
label variable Packaging "Indicator of Unboxed (0) or Boxed (1)"

table Order Packaging, contents(mean Bars) format(%6.2f)

by Order, sort : egen float no_front = total(Bars)
by Packaging, sort : egen float no_boxed = total(Bars)
by Both, sort : egen float no_both = total(Bars)

by Both, sort : egen float test = median(QueueNumber)

by Both, sort : egen float MedianProp = pc(QueueNumber)
generate Que1Q = 1 if MedianProp<=0.25
replace Que1Q=0 if Que1Q==.
generate Que2Q = 1 if MedianProp<=0.5 & MedianProp>0.25
replace Que2Q=0 if Que2Q==.
generate Que3Q = 1 if MedianProp<=0.75 & MedianProp>0.5
replace Que3Q=0 if Que3Q==.
generate Que4Q = 1 if MedianProp>0.75
replace Que4Q=0 if Que4Q==.
gen QuartileQue=Que1Q+2*Que2Q+3*Que3Q+4*Que4Q

label define Quartiles 1 "1st Quartile" 2 "2nd Quartile" 3 "3rd Quartile" 4 "4th Quartile"
label values QuartileQue Quartiles

log close
